package com.fong.spring_cloud_consumer_ribbon.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@Service
public class HelloService {

	@Autowired
	RestTemplate restTemplate;

	@HystrixCommand( fallbackMethod = "producerError" )
	public String sayHello( String name ) {
		return restTemplate.getForObject( "http://spring-cloud-producer/hello?name=" + name, String.class );
	}

	public String producerError( String name ) {
		return "sorry " + name + ", the method sayHello(String name) is error!";
	}
}
